import { createContext } from 'react'
import { createHashRouter, RouterProvider } from 'react-router-dom'
import routes from './config/router' 
import { useProducts, useCart } from '@/hooks'
const router = createHashRouter(routes)
export const ProductContext = createContext()
export const CartListContext = createContext()
function App() {
  const products = useProducts('/products')
  // cartList 组装的购物车数据 => 展示商品列表,计算金额
  // dispatch 操作 购物车列表数据
  const [ cartList, cartDispatch ] = useCart([])
  return(
    <ProductContext.Provider value={ products }>
      <CartListContext.Provider value={{ cartList, cartDispatch }}>
        <RouterProvider router={ router }/>
      </CartListContext.Provider>
    </ProductContext.Provider>
  )
}


export default App;
